<?php
//
// +------------------------------------------------------------------------+
// | PHP Version 5.4                                                        |
// +------------------------------------------------------------------------+
// | Copyright (c) All rights reserved.                                     |
// +------------------------------------------------------------------------+
// | 世纪车来车往(北京）网络科技有限公司 版权所有！                               |
// | TEL:010-63732365  HOTLINE:400-6688-365  EMAIL:clcw@clcw.com.cn         |
// | $Revision: 1.0 $                                                       |
// +------------------------------------------------------------------------+
// | Author: xiangminghu@clcw.com.cn                                        |
// +------------------------------------------------------------------------+
//

namespace AuctionBack\Controller;

use AuctionCore\CarDealer\RepairCheck;
use AuctionCore\Common\AjaxPage;
use Think\Log;

/**
 * 维保接口对账查询
 *
 * @author Xmh
 */
class RepairCheckAccountsController extends BaseController
{
    private $RepairCheck;

    public function __construct()
    {
        parent::__construct();
        $this->RepairCheck = new RepairCheck();
    }

    public function index()
    {
        $this->display();
    }

    /**
     * 维保接口对账查询列表
     */
    public function repair_check_accounts_list()
    {
        $page = I("get.p/d", 1);
        $limit = 10;
        $status = I('get.status/d', 1);
        $vin = I('get.vin', '', 'trim');
        $check_platform = I('get.check_platform/d');
        $start_time = I('get.start_time', '');
        $end_time = I('get.end_time', '');
        $data_from = I('get.data_from/d');
        $order_status = I('get.order_status/d', 0);
        $dealer_info = I('get.dealer_info', '', 'trim');
        $is_bill = I('get.is_bill',-1);
        $third_channel = I('get.third_channel/d', 0);
        $CheckAccounts = 1;
        if ($status == 1) {
            $params = [
                'status' => $status,
                'vin' => $vin,
                'check_platform' => $check_platform,
                'start_time' => $start_time,
                'end_time' => $end_time,
                'data_from' => $data_from,
                'order_status' => $order_status,
                'dealer_info' => $dealer_info,
                'third_channel' => $third_channel,
                'is_bill' => $is_bill,
                'check_accounts' => $CheckAccounts
            ];
            $result = $this->RepairCheck->get_dealer_repair_check_list($page, $limit, $params);
        } else {
            $params = [
                'vin' => $vin,
                'callertype'=> $check_platform,// 查询平台
                'begintime' =>$start_time,
                'endtime' => $end_time,
                'channel' => $third_channel, //第三方渠道
                'status' => 2,  //订单状态
                'page' => $page,
                'pagesize' => $limit
            ];
            $result = $this->RepairCheck->get_third_repair_check_list($params);
        }
        $total = $result['total'] > 0 ? $result['total'] : 0;
        $list = $result['list'] > 0 ? $result['list'] : [];
        $user_list = empty($result['user_list']) ?: $result['user_list'];
        $Page = new AjaxPage($total, $limit, "get_page");
        $Page->setConfig('theme', " %totalRow% %header% %nowPage%/%totalPage% 页 %first% %upPage% %prePage% %linkPage% %downPage% %nextPage% %end% %jumpform%");
        $page_show = $Page->show();

        $this->assign('p', $page);
        $this->assign('page', $page_show);
        $this->assign('list', $list);
        $this->assign('user_list', $user_list);
        $this->assign('status', $status);
        $this->display();
    }

    /**
     * 维保接口对账查询统计
     */
    public function repair_check_count()
    {
        $status = I('post.status/d', 1);
        $vin = I('post.vin', '', 'trim');
        $check_platform = I('post.check_platform/d');
        $start_time = I('post.start_time', '');
        $end_time = I('post.end_time', '');
        $data_from = I('post.data_from/d');
        $order_status = I('post.order_status/d', 0);
        $dealer_info = I('post.dealer_info', '', 'trim');
        $is_bill = I('post.is_bill',-1);
        $third_channel = I('post.third_channel/d', 0);
        if ($status == 1) {
            $params = [
                'status' => $status,
                'vin' => $vin,
                'check_platform' => $check_platform,
                'start_time' => $start_time,
                'end_time' => $end_time,
                'data_from' => $data_from,
                'order_status' => $order_status,
                'dealer_info' => $dealer_info,
                'is_bill' => $is_bill,
                'third_channel' => $third_channel
            ];
            $result = $this->RepairCheck->get_dealer_repair_check_account_count($params);
        } else {
           $params = [
                'vin' => $vin,
                'callertype'=> $check_platform,// 查询平台
                'begintime' =>$start_time,
                'endtime' => $end_time,
                'channel' => $third_channel, //第三方渠道
                'status' => 2,  //订单状态
            ];
            $result = $this->RepairCheck->get_third_repair_check_account_count($params);
        }
        $this->helpJsonResult('200', '', $result);
    }


}